#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
using namespace std;

void postTravel(int *pref,int *inf,int len,vector<int> &v){
	if( len==0 ) return;
	int leftNumberOfChid = find(inf,inf+len,*pref)-inf;
	postTravel(pref+1,inf,leftNumberOfChid,v);
	postTravel(pref+leftNumberOfChid+1,inf+leftNumberOfChid+1,len-(leftNumberOfChid+1),v);
	v.push_back(*pref);
}
int main(){
	freopen("in.txt","r",stdin);
	int n;
	cin >> n;
	int inTravel[n],preTravel[n];
	stack<int> s;
	for( int i=0,j=0,k=0; i<2*n; i++ ){
		string str;
		int x;
		cin >> str;
		if( str=="Push" ){
			cin >> x;
			s.push(x);
			preTravel[j++] = x;	
		} else{
			inTravel[k++] = s.top();
			s.pop();
		} 
	}
	vector<int> v;
	postTravel(preTravel,inTravel,n,v);
	for(int i=0; i<v.size(); i++ ){
		cout << (i==0? "":" ") <<v[i];
	}
	return 0;
}

